#Morris R G , Barthelemy M . Transport on Coupled Spatial Networks[J]. Physical Review Letters, 2012, 109(12):128703.
import Coupled_Network as cn
import netGen as ng 
import networkx as nx
import numpy as np
def get_coupling(net12, net1):
    #公式中的lambda，个人认为存在问题，独立网络和耦合网络的i,j间最短距离不相同怎么办？
#     net12 = cn.Coupled_Network(G,  T)
#     net1  = cn.Coupled_Network(G1, T)
#     #net2  = cn.Coupled_Network(G2, T)
#     net12.get_shortest_path()
# #     cnt = 0
# #     for i in range(len(G)):
# #         for j in range(len(G)):
# #             if(G[i][j] > 0 and G[i][j] < 1e3):
# #                     cnt += 1
# #     print(cnt)
#     net1.get_shortest_path()
#     #net2.get_shortest_path()
#     #print(net12.num_d)
    coupling = 0
    for i in range(0, net12.N):
        for j in range(0, net12.N):
            if(net12.num_d[i][j] == 0): continue
            theta_coupling = net12.num_d[i][j] - net1.num_d[i][j]
            if(net12.d[i][j] < net1.d[i][j]):
                theta_coupling = net12.num_d[i][j]
            theta = net12.num_d[i][j]
            coupling += net12.T[i][j] * theta_coupling / theta
    return coupling

n1, n2 = 100, 20
G, G1, G2 = ng.make_G(n1, n2 )
T, dt = ng.make_T1(G, len(G1), len(G2))
net12 = cn.Coupled_Network(G,  T)
net1  = cn.Coupled_Network(G1, T)
net12.get_shortest_path()
net1.get_shortest_path()
print(get_coupling(net12, net1))
print(net12.get_avg_shortest_path())
print(net12.get_gini())
